package com.yikao.mini.demo.place;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface RxzYikaoMiniPlaceMapper {
    @Delete({
        "delete from rxz_yikao_mini_place",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into rxz_yikao_mini_place (id, number, ",
        "name, nickname, ",
        "email, adress, lingdui, ",
        "fuzeren)",
        "values (#{id,jdbcType=VARCHAR}, #{number,jdbcType=VARCHAR}, ",
        "#{name,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR}, ",
        "#{email,jdbcType=VARCHAR}, #{adress,jdbcType=VARCHAR}, #{lingdui,jdbcType=VARCHAR}, ",
        "#{fuzeren,jdbcType=VARCHAR})"
    })
    int insert(RxzYikaoMiniPlace record);

    @Select({
        "select",
        "id, number, name, nickname, email, adress, lingdui, fuzeren",
        "from rxz_yikao_mini_place",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="number", property="number", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="nickname", property="nickname", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="adress", property="adress", jdbcType=JdbcType.VARCHAR),
        @Result(column="lingdui", property="lingdui", jdbcType=JdbcType.VARCHAR),
        @Result(column="fuzeren", property="fuzeren", jdbcType=JdbcType.VARCHAR)
    })
    RxzYikaoMiniPlace selectByPrimaryKey(String id);

    @Select({
        "select",
        "id, number, name, nickname, email, adress, lingdui, fuzeren",
        "from rxz_yikao_mini_place"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="number", property="number", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="nickname", property="nickname", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="adress", property="adress", jdbcType=JdbcType.VARCHAR),
        @Result(column="lingdui", property="lingdui", jdbcType=JdbcType.VARCHAR),
        @Result(column="fuzeren", property="fuzeren", jdbcType=JdbcType.VARCHAR)
    })
    List<RxzYikaoMiniPlace> selectAll();

    @Update({
        "update rxz_yikao_mini_place",
        "set number = #{number,jdbcType=VARCHAR},",
          "name = #{name,jdbcType=VARCHAR},",
          "nickname = #{nickname,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "adress = #{adress,jdbcType=VARCHAR},",
          "lingdui = #{lingdui,jdbcType=VARCHAR},",
          "fuzeren = #{fuzeren,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(RxzYikaoMiniPlace record);

    //    自定义模糊查询：
    @Select({
            "select",
            "id, number, name, nickname, email, adress, lingdui, fuzeren",
            "from rxz_yikao_mini_place",
            "where number like '%${keyword}%' or name like '%${keyword}%' or nickname like '%${keyword}%'  "
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="number", property="number", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="nickname", property="nickname", jdbcType=JdbcType.VARCHAR),
            @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
            @Result(column="adress", property="adress", jdbcType=JdbcType.VARCHAR),
            @Result(column="lingdui", property="lingdui", jdbcType=JdbcType.VARCHAR),
            @Result(column="fuzeren", property="fuzeren", jdbcType=JdbcType.VARCHAR)
    })
    List<RxzYikaoMiniPlace> fuzzySelectP(@Param("keyword") String keyword);

}